﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using App.Utilities.Web.Handlers;
using CRMBiz;
using Newtonsoft.Json;

namespace CRMWeb.WebServices
{
    /// <summary>
    /// Summary description for EmailTemplate
    /// </summary>
    public class EmailTemplate : BaseHandler
    {
        public override void OnMethodInvoke(OnMethodInvokeArgs e)
        {
            context.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
            context.Response.Cache.SetExpires(DateTime.MinValue);
            context.Response.Cache.SetNoStore();

            //e.Cancel = true;

            SetResponseContentType(ResponseContentTypes.HTML);
        }

        public override void AfterMethodInvoke(object result)
        {
            base.AfterMethodInvoke(result);
        }

        public void DisplayTemplateNode()
        {
            try
            {
                bool isSMS = false;
                string strJson = JsonConvert.SerializeObject(CategoryNodeHandler.GetCategoryNodesList(isSMS,false,false));
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void DisplayCategoryList()
        {
            try
            {
                bool isSMS = false;
                string strJson = JsonConvert.SerializeObject(CategoryNodeHandler.GetCategoryNodesList(isSMS, true,false));
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void GetEmailTemplateContentById(int EmailTemplateId)
        {
            try
            {
                string strJson = JsonConvert.SerializeObject(CategoryNodeHandler.GetEmailTemplateContent(EmailTemplateId));
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void EmailTemplateShowAll()
        {
            try
            {
                string strJson = JsonConvert.SerializeObject(EmailTemplateHandler.BindEmailTemplate());
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void getColumnName()
        {
            try
            {
                string strJson = JsonConvert.SerializeObject(EmailTemplateHandler.getColumnName());
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public int EmailTemplateUpdate(int EmailId, string TemplateFormat, string emailSubject, int CategoryID)
        {
            int intReturnValue = 0;
            try
            {
                intReturnValue = EmailTemplateHandler.UpdateEmailTemplate(EmailId, TemplateFormat, emailSubject, CategoryID);
            }
            catch (Exception)
            {
                throw;
            }
            return intReturnValue;
        }

        public int EmailTemplateAdd(string EmailTemplate, string TemplateFormat, string emailSubject,int CategoryID)
        {
            int intReturnValue = 0;
            try
            {
                intReturnValue = EmailTemplateHandler.AddEmailTemplate(EmailTemplate, TemplateFormat, emailSubject, CategoryID);
            }
            catch (Exception)
            {
                throw;
            }
            return intReturnValue;
        }

        public bool EmailTemplateDelete(int EmailId)
        {
            bool flag = false;
            try
            {
                flag = EmailTemplateHandler.DeleteEmailTemplate(EmailId);
            }
            catch (Exception)
            {
                throw;
            }
            return flag;
        }

        public void SelectAllEmailId()
        {
            try
            {
                string strJson = JsonConvert.SerializeObject(EmailTemplateHandler.BindEmailId());
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void SelectPasswordDef()
        {
            try
            {
                string strJson = JsonConvert.SerializeObject(EmailTemplateHandler.SelectPassword());
                context.Response.Write(strJson);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}